package o;

import android.util.Log;
import androidx.annotation.NonNull;
import java.util.Collections;
import java.util.List;
import o.sg.d;
import o.tg.a;
import o.vk.c;

class tw implements tg, d<Object>, a {
    private volatile c<?> ʼ;
    private final tj<?> ˊ;
    private Object ˋ;
    private ta ˎ;
    private int ˏ;
    private final a ॱ;
    private te ॱॱ;

    tw(tj<?> tjVar, a aVar) {
        this.ˊ = tjVar;
        this.ॱ = aVar;
    }

    public boolean ˎ() {
        if (this.ˋ != null) {
            Object obj = this.ˋ;
            this.ˋ = null;
            ˊ(obj);
        }
        if (this.ˎ != null && this.ˎ.ˎ()) {
            return true;
        }
        this.ˎ = null;
        this.ʼ = null;
        boolean z = false;
        while (!z && ॱ()) {
            List ॱˊ = this.ˊ.ॱˊ();
            int i = this.ˏ;
            this.ˏ = i + 1;
            this.ʼ = (c) ॱˊ.get(i);
            if (this.ʼ != null && (this.ˊ.ॱ().ˊ(this.ʼ.ˎ.ˎ()) || this.ˊ.ˊ(this.ʼ.ˎ.ˋ()))) {
                this.ʼ.ˎ.ˏ(this.ˊ.ˎ(), this);
                z = true;
            }
        }
        return z;
    }

    private boolean ॱ() {
        return this.ˏ < this.ˊ.ॱˊ().size();
    }

    private void ˊ(Object obj) {
        long ॱ = aaq.ॱ();
        try {
            ry ˊ = this.ˊ.ˊ(obj);
            uj.c tcVar = new tc(ˊ, obj, this.ˊ.ˊ());
            this.ॱॱ = new te(this.ʼ.ॱ, this.ˊ.ʼ());
            this.ˊ.ˋ().ˊ(this.ॱॱ, tcVar);
            if (Log.isLoggable("SourceGenerator", 2)) {
                Log.v("SourceGenerator", "Finished encoding source to cache, key: " + this.ॱॱ + ", data: " + obj + ", encoder: " + ˊ + ", duration: " + aaq.ˎ(ॱ));
            }
            this.ʼ.ˎ.ˏ();
            this.ˎ = new ta(Collections.singletonList(this.ʼ.ॱ), this.ˊ, this);
        } catch (Throwable th) {
            this.ʼ.ˎ.ˏ();
        }
    }

    public void ˏ() {
        c cVar = this.ʼ;
        if (cVar != null) {
            cVar.ˎ.ॱ();
        }
    }

    public void ॱ(Object obj) {
        tf ॱ = this.ˊ.ॱ();
        if (obj == null || !ॱ.ˊ(this.ʼ.ˎ.ˎ())) {
            this.ॱ.ˏ(this.ʼ.ॱ, obj, this.ʼ.ˎ, this.ʼ.ˎ.ˎ(), this.ॱॱ);
            return;
        }
        this.ˋ = obj;
        this.ॱ.ˋ();
    }

    public void ˏ(@NonNull Exception exception) {
        this.ॱ.ˋ(this.ॱॱ, exception, this.ʼ.ˎ, this.ʼ.ˎ.ˎ());
    }

    public void ˋ() {
        throw new UnsupportedOperationException();
    }

    public void ˏ(sa saVar, Object obj, sg<?> sgVar, rz rzVar, sa saVar2) {
        this.ॱ.ˏ(saVar, obj, sgVar, this.ʼ.ˎ.ˎ(), saVar);
    }

    public void ˋ(sa saVar, Exception exception, sg<?> sgVar, rz rzVar) {
        this.ॱ.ˋ(saVar, exception, sgVar, this.ʼ.ˎ.ˎ());
    }
}
